package com.springboot.springmvc.restful.crud.controller;

import com.springboot.springmvc.restful.crud.common.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//测试：全局异常处理
@RestController
public class HahaController {
    @RequestMapping("/haha")
    public R haha() {
        int i = 10 / 0;
        return R.success();//此时HelloController的异常处理，无法处理haha（）的异常
    }
    //异常处理优先级
    //1.本类 》 全局
    //2.精确 》 模糊
    @ExceptionHandler(ArithmeticException.class)
    public R handleException(Exception e) {
        System.out.println("【本类】-出现ArithmeticException");
        return R.error(500,e.getMessage());
    }
}

